<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .list{
            width: 500px;
            height: 500px;
            overflow: auto;
            background-color: skyblue;
        }
        .list div{
            height: 100px;
        }
    </style>
</head>

<body>
    <script src="../React-js/17.0/react.development17.0.js" type="text/javascript"></script>
    <script src="../React-js/17.0/react-dom.development17.0.js" type="text/javascript"></script>
    <script src="../React-js/17.0/babel.min.js" type="text/javascript"></script>
    <div id="test"></div>
    <script type="text/babel">
        class NewList extends React.Component{
            state = {
                list:[]
            }
            componentDidMount(){
                setInterval(()=>{
                    const { list } = this.state
                    let newList=list.length+1
                    this.setState({
                        list:[newList,...list]
                    })
                },500)
            }
            getSnapshotBeforeUpdate(){
                return this.refs.list.scrollHeight
            }
            componentDidUpdate(prevProps,prevState,height){
                this.refs.list.scrollTop+=this.refs.list.scrollHeight-height
            }
            render(){
                return (
                    <div className="list" ref="list">
                        {
                            this.state.list.map((item,index)=>{
                                return <div key={index}>xxxxxx--{item}</div>
                            })
                        }
                    </div>
                )
            }
        }
        ReactDOM.render(<NewList/>,document.querySelector('#test'))
    </script>
</body>
</html>